package com.bknc.sgolf.pgm.web;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.WebRequest;

import com.bknc.common.BkncMessageSource;
import com.bknc.common.JSONResponseUtil;
import com.bknc.sgolf.pgm.service.SgolfShopService;
import com.bknc.sgolf.pgm.service.SgolfShopVO;
import com.bknc.sgolf.pgm.service.SgolfTestVO2;

/**
 * @author Administrator
 *
 */
@Controller
public class SgolfShopController {
	
    
    @Resource(name = "SgolfShopService")
    private SgolfShopService aSgolfShopService;


    @RequestMapping(value="/SgolfShopSearchList.do")
	public ResponseEntity selectSgolfTestSearchList(@ModelAttribute("SgolfTestVO") SgolfShopVO sgolftestvo, 
                                   ModelMap model, @RequestParam Map<String, String> params) throws Exception {

	      System.out.println("==================>" + params.get("id")+"       ;;;");
	      
    	sgolftestvo.setKeyid(params.get("id"));
	    sgolftestvo.setMessage("정상적으로 조회되었습니다.");    	
		sgolftestvo.setSgolfShopList(aSgolfShopService.selectSgolfShopList(sgolftestvo));
		
		List <SgolfShopVO> SgolfShopList= (List)sgolftestvo.getSgolfShopList();
		
		((SgolfShopVO)SgolfShopList.get(0)).setMessage("searched sucessfully");
		
    	Object result = sgolftestvo.getSgolfShopList();
    	
		System.out.println("all :" + JSONResponseUtil.getJSONResponse(result));
		
    	
    	model.addAttribute("sgolfTestList", JSONResponseUtil.getJSONResponse(result));
    	
       // return "sgolftest";
    	return JSONResponseUtil.getJSONResponse(result);
    
	}
   
    @RequestMapping(value="/SgolfTestSearchList2.do")
	public ResponseEntity selectSgolfTestSearchList2(@ModelAttribute("SgolfTestVO2") SgolfTestVO2 sgolftestvo2, 
                                   ModelMap model) throws Exception {

    	
    	sgolftestvo2.setSgolfTestList2(aSgolfShopService.selectSgolfTestList2(sgolftestvo2));
    	Object result = sgolftestvo2.getSgolfTestList2();
    	
    	model.addAttribute("sgolfTestList", JSONResponseUtil.getJSONResponse(result));
    	
       // return "sgolftest";
    	return JSONResponseUtil.getJSONResponse(result);
    
	}
   
    @RequestMapping(value="/SgolfShopInsert.do")
	public ResponseEntity insertGolfShop(@ModelAttribute("SgolfShopVO") SgolfShopVO sgolfshopvo, 
                                   ModelMap model,@RequestParam Map<String, String> params) throws Exception {

    	
    	      System.out.println("==================>" + params.get("id")+"       ;;;");
    	      sgolfshopvo.setId(params.get("id"));
    	      sgolfshopvo.setShop_name(params.get("shop_name"));
    	      sgolfshopvo.setAddress(params.get("address"));
    	      sgolfshopvo.setTel1(params.get("tel1"));
    	      sgolfshopvo.setTel2(params.get("tel2"));
    	      
    	      sgolfshopvo.setMessage("정상적으로 조회되었습니다.");
    	      
    	      aSgolfShopService.insertSgolfShop(sgolfshopvo);
    	      
    	    //  List<SgolfShopVO> list = (List)sgolfshopvo; 
    	      Object result = (SgolfShopVO) sgolfshopvo;

       // for(String value : values) {
       //     System.out.println(value);    
       // }

   


    //	sgolftestvo.setId(id);
    	
   // 	sgolftestvo.setSgolfTestList2(aSgolfTestService.selectSgolfTestList2(sgolftestvo2));
   // 	Object result = sgolftestvo2.getSgolfTestList2();
    	
    //	model.addAttribute("sgolfTestList", JSONResponseUtil.getJSONResponse(result));
    	
       // return "sgolftest";
    	return JSONResponseUtil.getJSONResponse(result);
    	
    
	}
   
  }